//
//  CreateQiYeViewController.m
//  EnterpriseEdition
//
//  Created by ypj on 2021/10/9.
//
#define  SignImageHeight  (ScreenWidth-32.0)/3.0-14.0+40

#import "CreateQiYeViewController.h"
#import "UploadSignImageView.h"
#import "TiShiSignMessageView.h"
#import "QiYeLeiXingView.h"
#import "TiShiMoreMessageView.h"
#import "UplodaImageWithGongSi.h"
#import "CheLiangGuiMoTableViewCell.h"
#import "QiYeModel.h"
#import "PersonCenterViewController.h"
#import "DetailAddressTableViewCell.h"

@interface CreateQiYeViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong) UITableView       *  tableView;
@property(nonatomic,strong) NSMutableArray    *   dataSource;
@property(nonatomic,strong) NSMutableArray    *   iconArray;
@property(nonatomic,strong) NSString          *   vipMoneyType;
@property(nonatomic,strong) UplodaImageWithGongSi   *  imageView;
@property(nonatomic,strong) CommonChoseTypeRoleView *  choseTypeView;

@property(nonatomic,assign) NSInteger             pageTage;
@property(nonatomic,strong) UIImage           *   YYZZImage;//营业执照
@property(nonatomic,strong) UIImage           *   WTSImage;//委托书
@property(nonatomic,strong) UIImage           *   GSLOImage;//公司logo
@property(nonatomic,strong) UIImage           *   DLYYImage;//道路运输经营许可证
@property(nonatomic,strong) UIImage           *   QCJYImage;//汽车经营许可证
@property(nonatomic,assign) NSInteger             leftIndex;
@property(nonatomic,assign) NSInteger             centerIndex;
@property(nonatomic,assign) NSInteger            rightIndex;
@property(nonatomic,strong) NSMutableArray    *   imageDataArray;
@property(nonatomic,strong) NSMutableArray    *   cacheSaveFilePath;
@property(nonatomic,strong) NSString         *    enterpriseType;//企业类型
@property(nonatomic,strong) NSString         *    businessLicenseUrl;//营业执照
@property(nonatomic,strong) NSString         *    enterpriseName;//企业全称
@property(nonatomic,strong) NSString         *    socialCreditCode;//社会信用代码
@property(nonatomic,strong) NSString         *    enterpriseLocation;//企业所在地
@property(nonatomic,strong) NSString         *    enterpriseAddress;//企业详细地址
@property(nonatomic,strong) NSString         *    vehicleScale;//车辆规模
@property(nonatomic,strong) NSString         *    enterprisePhone;//公司联系方式
@property(nonatomic,strong) NSString         *    avatar;//公司logo
@property(nonatomic,strong) NSString         *    enterprisePhoto;//公司描述图
@property(nonatomic,strong) NSString         *    proxyStatementUrl;//委托书
@property(nonatomic,strong) NSString         *    transportationLicenseUrl;//道路运输许可证
@property(nonatomic,strong) NSString         *    taxiOperationLicenseUrl;//出租车经营许可证url
@property(nonatomic,strong) NSMutableArray    *    vehicleScaleArray;


@end

@implementation CreateQiYeViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self layoutCustomNav:self.view title:@"创建企业"];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.enterprisePhone = @"";
    self.vehicleScaleArray = [NSMutableArray array];
    [self getCheLiangGuiMo];
    // self.dataSource=[NSMutableArray arrayWithArray:@[@"企业全称",@"统一社会信用码",@"企业所在地",@"企业详细地址",@"车辆规模",@"公司联系方式"]];
    self.dataSource = [NSMutableArray arrayWithArray:@[@"企业全称",@"统一社会信用码",@"企业详细地址",@"车辆规模",@"对外联系方式"]];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, LL_StatusBarAndNavigationBarHeight, ScreenWidth, B_HEIGHT-LL_StatusBarAndNavigationBarHeight) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = White_Color;
    self.tableView.separatorColor = White_Color;
    [self.view addSubview:self.tableView];
    if(@available(iOS 11.0, *)){
            self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
    } else {
            self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self.tableView registerNib:[UINib nibWithNibName:[CommonTableViewCell reuseIdentifier] bundle:nil] forCellReuseIdentifier:[CommonTableViewCell reuseIdentifier]];
    [self.tableView registerNib:[UINib nibWithNibName:[CheLiangGuiMoTableViewCell reuseIdentifier] bundle:nil] forCellReuseIdentifier:[CheLiangGuiMoTableViewCell reuseIdentifier]];
    [self.tableView registerNib:[UINib nibWithNibName:[DetailAddressTableViewCell reuseIdentifier] bundle:nil] forCellReuseIdentifier:[DetailAddressTableViewCell reuseIdentifier]];

    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    CGRect frame = CGRectMake(0, 0, 0, 0.1);
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:frame];
    [self createUploadImage];
   
}



-(void)createUploadImage{
    self.imageDataArray = [NSMutableArray arrayWithArray:@[@"addPhoto_icon"]];
    self.cacheSaveFilePath=[NSMutableArray arrayWithArray:@[@""]];
    self.imageView = [UplodaImageWithGongSi shareInstance];
    [self.imageView setDataImageArray:self.imageDataArray];
    self.imageView.frame = CGRectMake(0, 0, ScreenWidth, 0);
    [self.imageView  getCollectionViewHeight];
     NSLog(@"--------%f",self.imageView.collectionViewHeight);
     self.imageView.frame = CGRectMake(0, 0, ScreenWidth, self.imageView.collectionViewHeight);
    [ self.imageView setToShowImage:^(UIImage * _Nonnull image){
            if (image){
                UIWindow *window = [BaseViewController getCurrentWindow];
                ShowBigImageWithFrameView *ImageShow = [[ShowBigImageWithFrameView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, B_HEIGHT) withImage:image];
                [window addSubview:ImageShow];
            }
        }];
        [self.tableView reloadData];
        BD_WEAKSELF
        [self.imageView setToShowAlert:^{
            if(self.cacheSaveFilePath.count - 1 >= 3){
                showAlert(@"最多上传3张公司描述图");
                return;
            }
            [weakSelf upDateHeaderImage:105];
        }];
        [self.imageView setToDelectImage:^(NSInteger index) {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确定删除图片吗?" message:@"" preferredStyle:UIAlertControllerStyleAlert];

            [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){

            }]];
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
                [weakSelf.imageView delectImageSure:index];
                [weakSelf.tableView reloadData];
            }]];
            [weakSelf  presentViewController:alert animated:true completion:nil];
        }];
        [self.imageView setToDelectFileUrl:^(NSInteger index){
             NSString *fileString = weakSelf.cacheSaveFilePath[index];
             [weakSelf delectUpdateInShopImg:fileString withIndex:index];
        }];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 6;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==1){
        return self.dataSource.count;
    } else {
        return 0;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==3) {
        CheLiangGuiMoTableViewCell  *cell = [self.tableView dequeueReusableCellWithIdentifier:[CheLiangGuiMoTableViewCell reuseIdentifier]];
        if (!cell){
         cell = [[CheLiangGuiMoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[CheLiangGuiMoTableViewCell reuseIdentifier]];
     }
        if (self.vehicleScale.length>0) {
            cell.numberLb.text = self.vehicleScale;
        } else {
            cell.numberLb.text = @"0";
        }
     cell.selectionStyle= UITableViewCellSelectionStyleNone;
     return cell;
    }else if(indexPath.row == 2){
        DetailAddressTableViewCell  *  cell=[self.tableView dequeueReusableCellWithIdentifier:[DetailAddressTableViewCell reuseIdentifier]];
        if (!cell){
         cell=[[DetailAddressTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[DetailAddressTableViewCell reuseIdentifier]];
        }
        cell.selectionStyle= UITableViewCellSelectionStyleNone;
        cell.nameLb.text=self.dataSource[indexPath.row];
        [cell.addressTV didChangeText:^(PlaceholderTextView *textView) {
             self.enterpriseAddress=textView.text;
        }];
        if (![NSString isNUllString:self.enterpriseAddress]){
            cell.addressTV.text=self.enterpriseAddress;
        } else {
            cell.addressTV.text=@"";
        }
        return cell;
     } else {
         
        CommonTableViewCell  *cell = [self.tableView dequeueReusableCellWithIdentifier:[CommonTableViewCell reuseIdentifier]];
        if (!cell){
        cell = [[CommonTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[CommonTableViewCell reuseIdentifier]];
        }
        cell.nameLb.text = self.dataSource[indexPath.row];
        cell.rightImage.hidden = YES;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.indexPath = indexPath;
        [cell setCurrentValueBlock:^(NSString * _Nonnull contentString, NSIndexPath * _Nonnull indexPath){
            if (indexPath.row == 0) {
                self.enterpriseName = contentString;
            }else if (indexPath.row == 1){
                self.socialCreditCode=contentString;
            }else if (indexPath.row == 4){
                self.enterprisePhone = contentString;
            }
        }];
        switch (indexPath.row){
            case 0:
            {
             cell.contentTF.placeholder = @"请输入企业全称";
             if(![NSString isNUllString:self.enterpriseName]){
                    cell.contentTF.text = self.enterpriseName;
                } else {
                cell.contentTF.text = @"";
                cell.contentTF.placeholder = @"请输入企业全称";
                }
                cell.contentTF.userInteractionEnabled=YES;
            }
            break;
            case 1:
            {
            cell.contentTF.placeholder = @"请输入统一社会信用码";
            if(![NSString isNUllString:self.socialCreditCode]){
                   cell.contentTF.text = self.socialCreditCode;
                } else {
                    cell.contentTF.text = @"";
                    cell.contentTF.placeholder = @"请输入统一社会信用码";
                  }
                cell.contentTF.userInteractionEnabled=YES;
                
            }
            break;
            case 2:
            {
//                cell.contentTF.userInteractionEnabled=NO;
//                if(self.enterpriseLocation.length== 0){
//                    cell.contentTF.placeholder=@"请选择企业所在地";
//                    cell.contentTF.text=@"";
//                } else {
//                    cell.contentTF.text=self.enterpriseLocation;
//                }
            }
            break;
            case 3:
            {
//                cell.contentTF.userInteractionEnabled=NO;
//                if (![NSString isNUllString:self.enterpriseAddress]){
//                    cell.contentTF.text=self.enterpriseAddress;
//                } else {
//                    cell.contentTF.text=@"";
//                    cell.contentTF.placeholder=@"";
//                }
            }
            break;
            case 4:
            {
                cell.contentTF.placeholder = @"请输入联系方式";
                cell.contentTF.userInteractionEnabled = YES;
                cell.contentTF.keyboardType = UIKeyboardTypeASCIICapable;
                if (self.enterprisePhone.length>0){
                    cell.contentTF.text = self.enterprisePhone;
                } else {
                cell.contentTF.placeholder = @"请输入联系方式";
                cell.contentTF.text = @"";
                }
            }
            break;
            default:
            break;
        }
        return cell;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 2){
       
        return [DetailAddressTableViewCell cellHeight];
        
    }else if(indexPath.row == 3){
        return [CheLiangGuiMoTableViewCell cellHeight];
      
        } else {
       
        return [CommonTableViewCell cellHeight];
       
        }
    
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    BD_WEAKSELF
    if (section == 0) {
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 58)];
        QiYeLeiXingView *vipView = [[QiYeLeiXingView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 58) withTag:[self.vipMoneyType intValue]];
        [vipView setToRefreshButtonTable:^(NSInteger selectTag){
            weakSelf.vipMoneyType = [NSString stringWithFormat:@"%ld",selectTag];
            if (selectTag == 830) {
                weakSelf.enterpriseType = @"租赁公司";
            }else if (selectTag == 831){
                weakSelf.enterpriseType = @"出租车";
            } else {
                weakSelf.enterpriseType = @"企业招募";
            }
             [weakSelf.tableView reloadData];
        }];
        vipView.typeLb.hidden = YES;
        [headerView addSubview:vipView];
        return headerView;
    }else if(section == 2){

        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SignImageHeight + 30)];
        UploadSignImageView *logoImage = [UploadSignImageView shareInstance];
        logoImage.frame = CGRectMake(0, 0, ScreenWidth, SignImageHeight);
        logoImage.checkButton.hidden = YES;
        logoImage.titleLb.text = @"公司展示图";
        logoImage.biChuanLb.text = @"(必传)";
        if (self.avatar.length > 0){
            [logoImage.addImageButton sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,self.avatar]] forState:UIControlStateNormal placeholderImage:Image(@"default_icon")];
        }
        [logoImage.addImageButton whenTapped:^{
            [self upDateHeaderImage:102];
        }];
        [headerView addSubview:logoImage];
        
        TiShiSignMessageView *messageView = [TiShiSignMessageView shareInstance];
        messageView.frame = CGRectMake(0, SignImageHeight, ScreenWidth, 30);
        messageView.messageLb.text = @"上传资料要求：请公司展示图或门头作为公司主图";
        [headerView addSubview:messageView];
        return headerView;
    }else if (section == 3){
        NSString  *messageString = @"上传资料要求：请上传最新道路运输经营许可证，或加盖红色企业公章的复印件（非电子公章），请确保输经营许可证完整清晰，便于识别。";
        CGFloat sizeheight = [messageString heightForSizeWithFont:[UIFont systemFontOfSize:13.0] andWidth:ScreenWidth-32];

        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SignImageHeight + sizeheight + 20)];
        UploadSignImageView *yingYeImage = [UploadSignImageView shareInstance];
        yingYeImage.frame = CGRectMake(0, 0, ScreenWidth, SignImageHeight);
        yingYeImage.checkButton.hidden = YES;
        yingYeImage.titleLb.text = @"道路运输经营许可证";
        yingYeImage.biChuanLb.text = @"(非必传)";
        if (self.transportationLicenseUrl.length > 0) {
            [yingYeImage.addImageButton sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,self.transportationLicenseUrl]] forState:UIControlStateNormal placeholderImage:Image(@"default_icon")];
            yingYeImage.delBtn.hidden = NO;
        }
        [yingYeImage.delBtn whenTapped:^{
            self.transportationLicenseUrl = @"";
            yingYeImage.delBtn.hidden = YES;
            [self.tableView reloadData];
        }];
        [yingYeImage.addImageButton whenTapped:^{
            [self upDateHeaderImage:103];
        }];
        
        [footerView addSubview:yingYeImage];
        
        TiShiMoreMessageView *moreMessage = [TiShiMoreMessageView shareInstance];
        moreMessage.frame = CGRectMake(0, SignImageHeight, ScreenWidth, sizeheight+45);
        moreMessage.messageLb.text = messageString;
        moreMessage.checkButton.hidden = YES;
        [footerView addSubview:moreMessage];
        return footerView;
    }else if(section== 4){
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 60)];
        UIButton *commitButton = [UIButton buttonWithType:UIButtonTypeCustom];
        commitButton.frame = CGRectMake(16, 9, ScreenWidth-32, 42);
        commitButton.backgroundColor = mainColor;
        commitButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
        [commitButton setTitleColor:White_Color forState:UIControlStateNormal];
        [commitButton createBordersWithColor:nil withCornerRadius:5.0 andWidth:0];
        [commitButton setTitle:@"提交" forState:UIControlStateNormal];
        [commitButton addTarget:self action:@selector(commitButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [headerView addSubview:commitButton];
        return headerView;
    } else {
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.1)];
        return headerView;
    }
}

-(void)commitButtonClick{
    [self commitInfo];
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 0) {
        NSString  *  messageString = @"上传资料要求：请上传最新三证合一的高清彩色版本企业营业执照，可加盖红色企业公章的复印件（非电子公章），请确保营业执照完整清晰，便于识别。";
        CGFloat sizeheight = [messageString heightForSizeWithFont:[UIFont systemFontOfSize:13.0] andWidth:ScreenWidth - 32];

        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SignImageHeight + sizeheight + 45)];
        UploadSignImageView *yingYeImage = [UploadSignImageView shareInstance];
        yingYeImage.frame = CGRectMake(0, 0, ScreenWidth, SignImageHeight);
        yingYeImage.checkButton.hidden = YES;
        yingYeImage.titleLb.text = @"营业执照";
        yingYeImage.biChuanLb.text = @"";
        if (self.businessLicenseUrl.length > 0){
            [yingYeImage.addImageButton sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,self.businessLicenseUrl]] forState:UIControlStateNormal placeholderImage:Image(@"default_icon")];
        }
        [yingYeImage.addImageButton whenTapped:^{
            [self upDateHeaderImage:100];
        }];
        
        [footerView addSubview:yingYeImage];
        
        TiShiMoreMessageView *moreMessage = [TiShiMoreMessageView shareInstance];
        moreMessage.frame = CGRectMake(0, SignImageHeight, ScreenWidth, sizeheight + 45);
        moreMessage.messageLb.text = messageString;
        UIImageView *cacheImage = [[UIImageView alloc] init];
        [cacheImage sd_setImageWithURL:[NSURL URLWithString:@"https://api-carlease-m.lixingpt.com/files/yyzz.jpg"]];
        moreMessage.checkButton.hidden=NO;
        [moreMessage.checkButton whenTapped:^{
            if (cacheImage){
                UIWindow *window = [BaseViewController getCurrentWindow];
                ShowBigImageWithFrameView *ImageShow = [[ShowBigImageWithFrameView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, B_HEIGHT) withImage:cacheImage.image];
                [window addSubview:ImageShow];
            }
        }];
        [footerView addSubview:moreMessage];
        return footerView;
    }else if(section == 1){
        
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.1)];
//        UploadSignImageView  * shouQuanImage =[UploadSignImageView shareInstance];
//        shouQuanImage.frame=CGRectMake(0, 0, ScreenWidth, SignImageHeight);
//        shouQuanImage.checkButton.hidden=NO;
//        shouQuanImage.titleLb.text=@"授权委托书";
//        shouQuanImage.biChuanLb.text=@"(非必传)";
//        if (self.proxyStatementUrl.length>0) {
//            [shouQuanImage.addImageButton sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,self.proxyStatementUrl]] forState:UIControlStateNormal placeholderImage:Image(@"default_icon")];
//        }
//        [shouQuanImage.addImageButton whenTapped:^{
//            [self upDateHeaderImage:101];
//        }];
//         UIImageView  *  cacheImage=[[UIImageView alloc] init];
//        [cacheImage sd_setImageWithURL:[NSURL URLWithString:@"https://carlease-mobile-dev.wycpt.com/files/dwwts.png"]];
//        [shouQuanImage.checkButton whenTapped:^{
//            if (cacheImage){
//                UIWindow  * window=[BaseViewController getCurrentWindow];
//                ShowBigImageWithFrameView * ImageShow = [[ShowBigImageWithFrameView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, B_HEIGHT) withImage:cacheImage.image];
//                [window addSubview:ImageShow];
//            }
//        }];
       // [footerView addSubview:shouQuanImage];
        return footerView;
    }else if (section == 2){
      //公司描述图片
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, self.imageView.collectionViewHeight + 30)];
        self.imageView.collectionView.frame = CGRectMake(16, 0, ScreenWidth-32.0, self.imageView.collectionViewHeight);
        footerView.backgroundColor = [UIColor redColor];
        [footerView addSubview:self.imageView];
        
        TiShiSignMessageView *messageView = [TiShiSignMessageView shareInstance];
        messageView.frame = CGRectMake(0, self.imageView.collectionViewHeight, ScreenWidth, 30);
        messageView.messageLb.text = @"上传资料要求：最多可上传1张";
        [footerView addSubview:messageView];
        return footerView;

    }else if(section == 3){
        NSString *messageString = @"上传资料要求：请上传最新出租汽车经营资格证，或加盖红色企业公章的复印件（非电子公章），请确保营业执照完整清晰，便于识别。";
        CGFloat sizeheight = [messageString heightForSizeWithFont:[UIFont systemFontOfSize:13.0] andWidth:ScreenWidth - 32];

        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SignImageHeight + sizeheight + 20)];
        UploadSignImageView *yingYeImage = [UploadSignImageView shareInstance];
        yingYeImage.frame = CGRectMake(0, 0, ScreenWidth, SignImageHeight);
        yingYeImage.checkButton.hidden = YES;
        yingYeImage.titleLb.text = @"出租汽车经营资格证";
        yingYeImage.biChuanLb.text = @"(非必传)";
        if (self.taxiOperationLicenseUrl.length > 0) {
            [yingYeImage.addImageButton sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",HTTP_URL,self.taxiOperationLicenseUrl]] forState:UIControlStateNormal placeholderImage:Image(@"default_icon")];
            yingYeImage.delBtn.hidden = NO;
        }
        [yingYeImage.delBtn whenTapped:^{
            self.taxiOperationLicenseUrl = @"";
            yingYeImage.delBtn.hidden = YES;
            [self.tableView reloadData];
        }];
        [yingYeImage.addImageButton whenTapped:^{
            [self upDateHeaderImage:104];
        }];
        [footerView addSubview:yingYeImage];
        
        TiShiMoreMessageView *moreMessage = [TiShiMoreMessageView shareInstance];
        moreMessage.frame = CGRectMake(0, SignImageHeight, ScreenWidth, sizeheight + 45);
        moreMessage.messageLb.text = messageString;
        moreMessage.checkButton.hidden = YES;
        [footerView addSubview:moreMessage];
        return footerView;
    } else {
         UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 90)];
         return footerView;
    }
 }
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 58;
    }else if (section == 1){
        return 0.1;
    }else if (section == 2){
        return SignImageHeight + 30;
    }else if (section == 3){
    NSString *messageString = @"上传资料要求：请上传最新道路运输经营许可证，或加盖红色企业公章的复印件（非电子公章），请确保营业执照完整清晰，便于识别。";
        CGFloat sizeheight = [messageString heightForSizeWithFont:[UIFont systemFontOfSize:13.0] andWidth:ScreenWidth - 32];
        return sizeheight + 20 + SignImageHeight;
    }else if (section == 4){
        return 60;
    } else {
        return 0;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0) {
        NSString *messageString = @"上传资料要求：请上传最新三证合一的高清彩色版本企业营业执照，可加盖红色企业公章的复印件（非电子公章），请确保营业执照完整清晰，便于识别。";
        CGFloat sizeheight = [messageString heightForSizeWithFont:[UIFont systemFontOfSize:13.0] andWidth:ScreenWidth - 32];
        return sizeheight + SignImageHeight + 45;
    }else if (section == 1){
        return 0.1;
    }else if (section == 2){
        return self.imageView.collectionViewHeight+30;
    }else if (section == 3){
        NSString *messageString = @"*上传资料要求：请上传最新出租汽车经营资格证，或加盖红色企业公章的复印件（非电子公章），请确保营业执照完整清晰，便于识别。";
        CGFloat sizeheight = [messageString heightForSizeWithFont:[UIFont systemFontOfSize:13.0] andWidth:ScreenWidth - 32];
        return  sizeheight + SignImageHeight + 20;
    }
    return 70;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    BD_WEAKSELF
//    if (indexPath.row==2) {
//        ChoseCityViewController   *   choseVC =[[ChoseCityViewController alloc] init];
//        [choseVC setToSendValue:^(NSString * _Nonnull province, NSString * _Nonnull city, NSString * _Nonnull quString, NSInteger leftIndex, NSInteger centerIndex, NSInteger rightIndex) {
//            weakSelf.leftIndex=leftIndex;
//            weakSelf.centerIndex=centerIndex;
//            weakSelf.rightIndex=rightIndex;
//            weakSelf.enterpriseLocation=[NSString stringWithFormat:@"%@%@%@",province,city,quString];
//            [weakSelf.tableView reloadData];
//        }];
//        [self.navigationController pushViewController:choseVC animated:YES];
//    }else
        if (indexPath.row == 3)
    {
        UIWindow *currentWindow = [BaseViewController getCurrentWindow];
         [weakSelf.view endEditing:YES];
        if(weakSelf.choseTypeView){
           [weakSelf.choseTypeView removeFromSuperview];
         }
         weakSelf.choseTypeView = [CommonChoseTypeRoleView  shareInstance];
         weakSelf.choseTypeView.frame = CGRectMake(0, 0, ScreenWidth, B_HEIGHT);
         [weakSelf.choseTypeView DataSourceToShowAlert:weakSelf.vehicleScaleArray withSelectTitle:weakSelf.vehicleScale withType:@"1" withTitle:@"请选则车辆规模"];
       
         [currentWindow addSubview:weakSelf.choseTypeView];
         [currentWindow bringSubviewToFront:weakSelf.choseTypeView];
        [weakSelf.choseTypeView setToSendValue:^(JueSeModel * _Nonnull model) {
            weakSelf.vehicleScale = model.value;
            [weakSelf.tableView reloadData];
           [weakSelf.choseTypeView removeFromSuperview];
        }];
        [weakSelf.choseTypeView.tableView reloadData];
    }
}

-(void)createRightButtonItem{
    UIButton   *  eduitButton=[UIButton buttonWithType:UIButtonTypeCustom];
     eduitButton.frame=CGRectMake(ScreenWidth-45,  KStatuesBarHeight, 30, 30);
    [eduitButton setImage:Image(@"AddPerson_icon") forState:UIControlStateNormal];
    [eduitButton addTarget:self action:@selector(EduitButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:eduitButton];
}

-(void)EduitButtonClick{
   
}

#pragma mark---上传图片
-(void)upDateHeaderImage:(NSInteger)tag{
    
    UIAlertController *alertvc = [UIAlertController alertControllerWithTitle:@"上传照片" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
        UIAlertAction *myLibraryAction = [UIAlertAction actionWithTitle:@"从相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            NSInteger sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
                PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
                if (status == PHAuthorizationStatusDenied || status == PHAuthorizationStatusRestricted) {
                    //相册权限受限制
                    showAlert(@"请前往设置-隐私-相机-利行租赁端-允许访问");
                    return;
                }
            }
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
             imagePickerController.modalPresentationStyle = 0;
            [imagePickerController.navigationBar setTintColor:[UIColor blackColor]];
            imagePickerController.delegate = self;
            imagePickerController.allowsEditing = NO;
            imagePickerController.sourceType = sourceType;
            imagePickerController.view.tag=tag;
            [self presentViewController:imagePickerController animated:YES completion:^{}];
        }];
        [alertvc addAction:myLibraryAction];
        UIAlertAction *daildAction = [UIAlertAction actionWithTitle:@"拍照上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        // 判断是否支持相机
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            
            NSUInteger sourceType = UIImagePickerControllerSourceTypeCamera;

            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
                PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
                if (status == PHAuthorizationStatusDenied || status == PHAuthorizationStatusRestricted) {
                    //相册权限受限制
                    showAlert(@"请前往设置-隐私-相机-利行租赁端-允许访问");
                    return;
                }
            }
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
             imagePickerController.modalPresentationStyle = 0;
            [imagePickerController.navigationBar setTintColor:[UIColor blackColor]];
            imagePickerController.delegate = self;
            imagePickerController.allowsEditing = NO;
            imagePickerController.sourceType = sourceType;
            imagePickerController.view.tag = tag;
            [self presentViewController:imagePickerController animated:YES completion:^{}];
        }
    }];
    [alertvc addAction:daildAction];
    UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    }];
    [alertvc addAction:cancelAction];
    [self presentViewController:alertvc animated:YES completion:nil];
}
#pragma mark - image picker delegte
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:YES completion:^{}];
     UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
    //暂存本地图片
        self.pageTage=picker.view.tag;
        NSMutableArray * tmpAry = [NSMutableArray array];
        NSData * data = [image compressMidQualityWithLengthLimit:kPhotoFileSize];
        UIImage * img0 = [UIImage imageWithData:data];
        YLUploadMedia * imageM = [YLUploadMedia mediaWithType:YLUploadMediaTypeJpg mediaName:nil mimeName:@"file" obj:img0];
        [tmpAry addObject:imageM];
        NSLog(@"<<-- 原尺寸:%@  新尺寸:%@  大小:%.4fMB -->>", NSStringFromCGSize(image.size), NSStringFromCGSize(img0.size),(double)data.length / 1024.0f / 1024.0f);
         [self shanChuanImageWithArray:tmpAry ];
}

///上传图片
-(void)shanChuanImageWithArray:(NSMutableArray *)tmpAry{
    

    [MSNetworkManager postRevertUrl:POST_UploadFile_URL params:@{@"type":@"1"} formData:tmpAry success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        if (isSuccess) {
            if (self.pageTage == 100) {
                self.businessLicenseUrl = resonseObj[@"url"];
                [self getYingYeZhiZhaoURl];
            }else if (self.pageTage == 101){
                self.proxyStatementUrl = resonseObj[@"url"];
                [self.tableView reloadData];
            }else if (self.pageTage == 102){
                self.avatar = resonseObj[@"url"];
                [self.tableView reloadData];
            }else if (self.pageTage == 103){
                self.transportationLicenseUrl = resonseObj[@"url"];
                [self.tableView reloadData];
            }else if (self.pageTage == 104){
                self.taxiOperationLicenseUrl = resonseObj[@"url"];
                [self.tableView reloadData];
            } else {
                NSString  * fileString = resonseObj[@"url"];
                [self.imageView.imageArray insertObject:fileString atIndex:self.imageDataArray.count-1];
                [self.cacheSaveFilePath insertObject:fileString atIndex:self.cacheSaveFilePath.count-1];
                [self.imageView getCollectionViewHeight];
                self.imageView.height=self.imageView.collectionViewHeight;
                [self.imageView.collectionView reloadData];
            }
            
        }
        
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
        
    } withShowHud:YES];
    
   
}

///获取营业执照url
-(void)getYingYeZhiZhaoURl{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
//    [params setObject:[NSString stringWithFormat:@"%@",self.businessLicenseUrl ] forKey:@"url"];

   [params setObject:[NSString stringWithFormat:@"%@%@",HTTP_URL,self.businessLicenseUrl] forKey:@"url"];
   [params setObject:@"2" forKey:@"cmd"];
  
    
    [MSNetworkManager postRevertUrl:OCR_URL params:params success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        
        if (isSuccess) {
            NSString   *dataString = resonseObj;
            NSDictionary  *infoDic = [BaseViewController parseJSONStringToNSDictionary:dataString];
            self.enterpriseName = infoDic[@"words_result"][@"单位名称"][@"words"];
            self.socialCreditCode = infoDic[@"words_result"][@"社会信用代码"][@"words"];
            self.enterpriseAddress = infoDic[@"words_result"][@"地址"][@"words"];
            [self.tableView reloadData];
        }
        
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
    } withShowHud:YES];
    

}

-(void)delectUpdateInShopImg:(NSString *)fileUrl withIndex:(NSInteger)index{
    BD_WEAKSELF
    [weakSelf.cacheSaveFilePath removeObjectAtIndex:index];
    [self.imageView.collectionView reloadData];

}
-(void)commitInfo{
    [self.view endEditing:YES];
    NSMutableDictionary   *params = [NSMutableDictionary dictionary];
    if (self.enterpriseType.length== 0) {
        showAlert(@"企业类型不能为空");
        return;
    }
    [params setObject:self.enterpriseType forKey:@"enterpriseType"];
   
    if (self.businessLicenseUrl.length == 0) {
        showAlert(@"请上传营业执照");
        return;
    }
    [params setObject:self.businessLicenseUrl forKey:@"businessLicenseUrl"];

    if (self.socialCreditCode.length == 0) {
        showAlert(@"社会信用代码不能为空");
        return;
    }
    [params setObject:self.socialCreditCode forKey:@"socialCreditCode"];

    if (self.enterpriseName.length == 0) {
        showAlert(@"企业名称不能为空");
        return;
    }
    [params setObject:self.enterpriseName forKey:@"enterpriseName"];
//    if (self.enterpriseLocation.length== 0) {
//        showAlert(@"企业所在地不能为空");
//        return;
//    }
//    [params setObject:self.enterpriseLocation forKey:@"enterpriseLocation"];

    if (self.enterpriseAddress.length== 0) {
        showAlert(@"企业详细地址不能为空");
        return;
    }
    [params setObject:self.enterpriseAddress forKey:@"enterpriseAddress"];
    if (self.vehicleScale.length== 0) {
        showAlert(@"车辆规模不能为空");
        return;
    }
    [params setObject:self.vehicleScale forKey:@"vehicleScale"];
    if (self.enterprisePhone.length== 0) {
        showAlert(@"对外联系方式不能为空");
        return;
    }
    [params setObject:self.enterprisePhone forKey:@"enterprisePhone"];
//    if (self.proxyStatementUrl.length>0){
//        [params setObject:self.proxyStatementUrl forKey:@"proxyStatementUrl"];
//    }
   

    if (self.avatar.length == 0){
        showAlert(@"请上传公司展示图");
        return;
    }
   [params setObject:self.avatar forKey:@"logoUrl"];
    NSString  * cacheSaveFileArrayStr=[[NSString alloc] init];
    NSMutableArray  * cacheArray=[NSMutableArray array];
    if (self.cacheSaveFilePath.count-1== 0) {
        showAlert(@"请至少上传一张公司描述图");
        return;
    }
    for (int i = 0; i < self.cacheSaveFilePath.count - 1; i++){
        NSString *cacheString = self.cacheSaveFilePath[i];
        [cacheArray addObject:cacheString];
    }
    for(NSString *  string in cacheArray){
        cacheSaveFileArrayStr=[NSString stringWithFormat:@"%@,%@",cacheSaveFileArrayStr,string];
    }
    if (cacheSaveFileArrayStr.length>0){
        cacheSaveFileArrayStr = [cacheSaveFileArrayStr substringFromIndex:1];
        self.enterprisePhoto = cacheSaveFileArrayStr;
    }
    if (self.enterprisePhoto.length > 0){
        [params setObject:self.enterprisePhoto forKey:@"enterprisePhoto"];
    }

    if(self.transportationLicenseUrl.length>0){
        [params setObject:self.transportationLicenseUrl forKey:@"transportationLicenseUrl"];
    }
    if (self.taxiOperationLicenseUrl.length>0){
        [params setObject:self.taxiOperationLicenseUrl forKey:@"taxiOperationLicenseUrl"];
    }

    
    [MSNetworkManager postRevertUrl:QY_URL params:params success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        if (isSuccess) {
            
            showAlert(@"创建企业成功");
            
            [JPUSHService setAlias:USER_ID completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
                NSLog(@"");
            } seq:1];
            
            NSDictionary *sysUser = resonseObj[@"sysUser"];
            NSDictionary *enterprise = resonseObj[@"enterprise"];
            
            [self saveUserInfo:sysUser];
            YLUserInfo * info = [YLUserMgr fetchUser];
            info.nickName = sysUser[@"nickName"];
            info.userId =  sysUser[@"userId"];
            info.companyId = sysUser[@"companyId"];
            info.enterpriseName = sysUser[@"enterpriseName"];
            info.workAddress = sysUser[@"workAddress"];
            info.username = sysUser[@"username"];
            info.carNum = sysUser[@"carNum"];
            info.logoUrl = enterprise[@"logoUrl"];
            info.avatar = enterprise[@"avatar"];
            
            NSDictionary *roleDic = [resonseObj[@"userInfo"][@"roleList"] firstObject];
            info.roleId = roleDic[@"roleId"];
            info.roleName = roleDic[@"roleName"];
            

            // 获取个人信息保存
            [self getUserInfo:^(BOOL isSuccess) {
                
            }];
           
           
           [[MSStorageUtils shareInstance] userDefaultSave:info.roleName withKey:COMPANY_ROLE_NAME];

            
           [YLUserMgr saveUser:info];
           if (self.isFromeLogin == YES){
                UIWindow  *  currentWindow=[BaseViewController getCurrentWindow];
                LiXingMainTabbarVC *tabBarController = [[LiXingMainTabbarVC alloc] init];
                tabBarController.delegate = self;
                tabBarController.selectedIndex = 0;
                [currentWindow setRootViewController:tabBarController];
                [currentWindow makeKeyAndVisible];
           } else {
               for (UIViewController *controller in self.navigationController.viewControllers){
                       if ([controller isKindOfClass:[PersonCenterViewController class]]){
                           PersonCenterViewController *messageVC =(PersonCenterViewController *)controller;
                            [self.navigationController popToViewController:messageVC animated:YES];
                    }
                }
           }
       }
       
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
    } withShowHud:YES];
    

}

-(void)getCheLiangGuiMo{
    
    
    NSArray *ary =  kUserDefaultForKey(k_CLGM);
    
    self.vehicleScaleArray = [JueSeModel mj_objectArrayWithKeyValuesArray:ary];
    
}

@end
